<template>
  <el-row :gutter="20">
    <el-col :span="2">
      <div class="grid-content bg-purple">
        <div>&emsp;&emsp;&emsp;</div>
      </div>
    </el-col>
    <el-col :span="20">
      <div class="grid-content bg-purple">
        <div style="height: 10px;"></div>
        <div>
          <!--查询表单-->
          <el-form :inline="true" class="demo-form-inline">
            <el-form-item>
              <el-input v-model="condition.name" placeholder="用户名" />
            </el-form-item>

            <el-form-item>
              <el-select v-model="condition.level" clearable placeholder="用户类型">
                <el-option :value="1" label="高级讲师" />
                <el-option :value="2" label="首席讲师" />
              </el-select>
            </el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="query()">查询</el-button>
            <el-button type="default" @click="resetData()">清空</el-button>
            <!-- <router-link > -->
            <el-button @click="Jump" type="success">添加用户</el-button>
          </el-form>
        </div>
        <div class="grid-content bg-purple-dark">
          <el-table
            ref="singleTable"
            :data="tableData"
            highlight-current-row
            @current-change="handleCurrentChange"
            style="width: 100%"
          >
            <el-table-column type="index" width="50"></el-table-column>
            <el-table-column property="username" label="用户名" width="120"></el-table-column>
            <el-table-column property="sex" label="性别" width="120"></el-table-column>
            <el-table-column property="type" label="类型"></el-table-column>
            <el-table-column property="gmtCreate" label="创建时间"></el-table-column>
            <el-table-column property="remarks" label="备注"></el-table-column>
            <el-table-column label="操作" width="200" align="center">
              <template slot-scope="scope">
                <router-link :to="'/stuteacher/addUser/'+scope.row.id">
                  <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
                </router-link>
                <el-button
                  type="danger"
                  size="mini"
                  icon="el-icon-delete"
                  @click="removeDataById(scope.row.id)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页 -->
          <el-pagination
            :current-page="page.current"
            :page-size="page.size"
            :total="page.total"
            style="padding: 30px 0; text-align: center;"
            layout="total, prev, pager, next, jumper"
            @current-change="getlist"
          />
        </div>
      </div>
    </el-col>
    <el-col :span="2">
      <div class="grid-content bg-purple"></div>
    </el-col>
  </el-row>
</template>
<script>
import eduUser from "@/api/eduUser";

export default {
  data() {
    return {
      tableData: [],
      page: {
        current: 1,
        size: 10,
        total: 0
      }, //分页查询
      condition: {} // 请求参数
    };
  },
  created() {
    this.getlist();
  },
  methods: {
    // 查询列表
    getlist(page = 1) {
      // debugger
      this.page.current = page;
      eduUser
        .query(this.page, this.condition)
        .then(response => {
          // console.log(response.data.list.records);
          this.tableData = response.data.list.records;
          this.page.current = response.data.list.current;
          this.page.list = response.data.list.list;
          this.page.total = response.data.list.total;
        })
        .catch(); //请求失败执行
    },
    //删除数据
    removeDataById(id) {
      this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return eduUser.del(id).then(() => {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.getlist();
          });
        })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!"
          });
          this.query();
        })
        .catch(response => {
          // 失败
          if (response === "cancel") {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
          }
        });
    },
    handleCurrentChange() {},
    Jump() {
      this.$router.push({
        path: "/stuteacher/addUser/" 
      });
    }
  }
};
</script>

<style>
.s {
}
</style>